package com.afc.struts.test.model;

import java.util.Date;

import com.afc.struts.annotations.PossibleValues;
import com.afc.struts.test.data.PersonDao;

public interface Person
{
  public int getId();
  public void setId(int aId);

  public String getFirstName();
  public void setFirstName(String aFirstName);

  public String getLastName();
  public void setLastName(String aLastName);

  public Double getSize();
  public void setSize(Double aSize);

  public Date getBirthday();
  public void setBirthday(Date aBirthday);

  public Person getBestFriend();
  public void setBestFriend(Person aBestFriend);

  public class DefaultPerson implements Person
  {
    public DefaultPerson(String aFirstName, String aLastName, Double aSize, Date aBirthday, Person aBestFriend)
    {
      firstName = aFirstName;
      lastName = aLastName;
      size = aSize;
      birthday = aBirthday;
      if (aBestFriend != null)
      {
        bestFriendId = aBestFriend.getId();
      }
    }

    @Override
    public int getId()
    {
      return id;
    }

    @Override
    public void setId(int aId)
    {
      id = aId;
    }

    @Override
    public String getFirstName()
    {
      return firstName;
    }

    @Override
    public void setFirstName(String aFirstName)
    {
      firstName = aFirstName;
    }

    @Override
    public String getLastName()
    {
      return lastName;
    }

    @Override
    public void setLastName(String aLastName)
    {
      lastName = aLastName;
    }

    @Override
    public Double getSize()
    {
      return size;
    }

    @Override
    public void setSize(Double aSize)
    {
      size = aSize;
    }

    @Override
    public Date getBirthday()
    {
      return birthday;
    }

    @Override
    public void setBirthday(Date aBirthday)
    {
      birthday = aBirthday;
    }

    @Override
    @PossibleValues("getPossibleBestFriends")
    public Person getBestFriend()
    {
      return PersonDao.getInstance().retrieve(bestFriendId);
    }

    @Override
    public void setBestFriend(Person aBestFriend)
    {
      if (aBestFriend != null)
      {
        bestFriendId = aBestFriend.getId();
      }
      else
      {
        bestFriendId = 0;
      }
    }

    @Override
    public String toString()
    {
      return firstName + " " + lastName;
    }

    protected int id;
    protected String firstName;
    protected String lastName;
    protected Double size;
    protected Date birthday;
    protected int bestFriendId;
  }
}
